const { userMsg } = require('./requestUserMsg');

module.exports = () => {
    return async function validateAdmin(ctx, next) {
        try {
            let userInfo = userMsg(ctx);
            if (userInfo.hasOwnProperty('code') && userInfo.code != 200) {
                throw userInfo;
            }
            if (!userInfo.hasOwnProperty('limit') || userInfo.limit.indexOf('backLogin') === -1) {
                throw ctx.helper.getErrorMsg(202);
            } else {
                await next();
            }
        } catch (obj) {
            ctx.response.body = obj;
        }
    }

}